<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网点库存</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	     <!-- 页面  -->
	    <section class="AllContent" style="background-color: #fff;padding-bottom:0px;">
	    	<div id="stocklist">
	    		<!-- 查询输入框 -->
				<div class="QueryInput">
					<ul>
						<li><input type="tetx" id="query"
	                       onkeypress="if (event.keyCode == 13) {
	                                                   proccessTextArea();
	                                                   return false;
	                                               }"
	                                       placeholder="输入产品编号或者产品名称"/></li>
						<li><button type="button" onclick="proccessTextArea();">查询</button></li>
					</ul>
				</div>
				
				<!-- 产品信息 -->
				<div class="ProductInformation">
					<ul>
						<li>
							<p>产品名称</p>
							<p style="color:#47a8ef" id="pname">Null</p>
						</li>
						<li>
							<p>总库存</p>
							<p id="qty" style="color:#f60">0</p>
						</li>
					</ul>
				</div>
				
				<!-- 信息 -->
				<div class="StockNav">
					<ul>
						<li>网点名称</li>
						<li>网点编号</li>
						<li>库存数</li>
					</ul>
				</div>
					
				<div id="branchlist">

                </div>
				
	    	</div>
	    </section>
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init();
		$('.AllHeader li:eq(1)').text('网点库存');
		
		$(function () {
            $pid = $_GET['pid'];
            $("#query").val($pid);
            proccessTextArea()
        });


        function proccessTextArea() {
            var q = $("#query").val();
            if (empty(q)) {
                alertMessage("产品名称或者产品编号！");
            } else {
                $.ajax({//一个Ajax过程
                    type: "post", //以post方式与后台沟通
                    url: getServerUrl() + "/Open/ComStat/stock",
                    dataType: 'json', //从php返回的值以 JSON方式 解释
                    data: 'product=' + q+'&access_token='+getToken(),
                    success: function (json) {//如果调用php成功
                        if (json.result == "1") {
                            $("#pid").text(json.pid);
                            $("#pname").text(json.pname);
                            $("#qty").text(json.qty);
                            var html = "";
                            if(!empty(json.branchlist)) {
                                for (var i = 0; i < json.branchlist.length; i++) {
									html = html +'<ul>'
												+'<li>'+json.branchlist[i].branch_name+'</li>'
												+'<li>'+json.branchlist[i].bid+'</li>'
												+'<li>'+json.branchlist[i].count+'</li>'
												+'</ul>';
                                }
                            }
                            $("#branchlist").html(html);
                            /* 高度设置  */
							var WinH = $(window).height();
							var CrH = $('.ContainerRight').height();
							var ClH = $('.ContainerLeft').height();
							if(CrH>ClH && CrH>WinH){
								$('.ContainerLeft').height(CrH);
							}else{
								$('.ContainerLeft').height(ClH+20);
							}
                        } else {
                            alertMessage("查询数据异常:[" + json.error_description + "]");
                        }
                    }
                });
            }
        }

        function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        function onBackKeyDown() {
            openUrl("index.html");
        }
        
		var mySwiper = new Swiper('.swiper-container',{
			watchSlidesProgress : true,
			watchSlidesVisibility : true,
			slidesPerView :4,
			prevButton:'.swiper-button-prev',
			nextButton:'.swiper-button-next',
		})
        
		var mySwiper = new Swiper('.swiper-container',{
			watchSlidesProgress : true,
			watchSlidesVisibility : true,
			slidesPerView :4,
			prevButton:'.swiper-button-prev',
			nextButton:'.swiper-button-next',
		})
	</script>
</html>
